{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "06e11541-2c8b-41de-8a74-4679b80738d0",
   "metadata": {},
   "source": [
    "Chapter 09\n",
    "# 定义、使用“鸡”类\n",
    "Book_1《编程不难》 | 鸢尾花书：从加减乘除到机器学习  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "fadb7884-096b-4ce1-8476-7e111b737d59",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 创建了一个名为 \"Chicken\" 的类\n",
    "class Chicken:\n",
    "    def __init__(self, name, age, color, weight):\n",
    "    # 初始化对象的属性\n",
    "        # 设置实例变量self.name来存储小鸡名字\n",
    "        self.name = name\n",
    "        # 设置实例变量self.age来存储小鸡年龄\n",
    "        self.age = age\n",
    "        # 设置实例变量self.color来存储小鸡体色\n",
    "        self.color = color\n",
    "        # 设置实例变量self.weight来存储小鸡体重          \n",
    "        self.weight = weight"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "74689295-8946-4cf9-9542-d9941d18cc44",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 调用Chicken类\n",
    "chicken_01 = Chicken(\"小红\", 1, \"黄色\", 1.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "659d71e4-45ce-4b05-a07a-b65e193404d6",
   "metadata": {},
   "outputs": [],
   "source": [
    "chicken_02 = Chicken(\"小黄\", 1.2, \"红色\", 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "14693524-737c-467f-b925-0356f07dab5a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "==小鸡的名字==\n",
      "小红\n",
      "==小鸡的年龄，yr==\n",
      "1\n",
      "==小鸡的颜色==\n",
      "黄色\n",
      "==小鸡的体重，kg==\n",
      "1.5\n"
     ]
    }
   ],
   "source": [
    "print('==小鸡的名字=='); print(chicken_01.name)\n",
    "print('==小鸡的年龄，yr=='); print(chicken_01.age)\n",
    "print('==小鸡的颜色=='); print(chicken_01.color)\n",
    "print('==小鸡的体重，kg=='); print(chicken_01.weight)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
